package com.enjoy.game.xcard.action;

import org.andengine.entity.IEntity;
import org.andengine.entity.modifier.IEntityModifier;
import org.andengine.entity.modifier.IEntityModifier.IEntityModifierListener;
import org.andengine.entity.modifier.MoveYModifier;
import org.andengine.entity.modifier.PathModifier;
import org.andengine.entity.modifier.PathModifier.Path;
import org.andengine.util.modifier.IModifier;

import com.enjoy.game.xcard.sprite.CellLayout;
import com.enjoy.game.xcard.sprite.XCard;


public class MovementController implements  IEntityModifierListener{
	PathModifier mModifier;
	CellLayout mDestCell;
	
	
	public MovementController(CellLayout mDestCell) {
		this.mDestCell = mDestCell;
	}


	public void triger(final XCard card, final CellLayout srcCell){
		
		if(mDestCell != null && mDestCell.acceptCard()){
			srcCell.removeCard(card);
			srcCell.getParent().attachChild(card);
			MoveYModifier modifier = new MoveYModifier(1.0f, card.getY(), mDestCell.getY(), this);
			modifier.setAutoUnregisterWhenFinished(true);
			card.registerEntityModifier(modifier);
		}
		
	}
	
	@Override
	public void onModifierStarted(IModifier<IEntity> pModifier, IEntity pItem) {

		
	}
	
	@Override
	public void onModifierFinished(IModifier<IEntity> pModifier, IEntity pItem) {
		pItem.detachSelf();
		mDestCell.putCard((XCard)pItem);
	}

}
